package com.example.teaculture.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.teaculture.R;
import com.example.teaculture.tools.FileCacheUtils;

public class SettingsActivity extends AppCompatActivity implements View.OnClickListener {

  private TextView about_app, app_language, welcome_app, clear_cache, app_notice;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.seting_activity);
    welcome_app = findViewById(R.id.welcome_app);
    app_language = findViewById(R.id.app_language);
    about_app = findViewById(R.id.about_app);
    clear_cache = findViewById(R.id.clear_cache);
    app_notice = findViewById(R.id.app_notice);
    app_notice.setOnClickListener(this);
    welcome_app.setOnClickListener(this);
    app_language.setOnClickListener(this);
    about_app.setOnClickListener(this);
    clear_cache.setOnClickListener(this);
  }


  public void stback(View view){
    this.finish();
  }

  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.app_notice: {
         Toast.makeText(this,"暂未实现",Toast.LENGTH_SHORT).show();
      }
      break;
      case R.id.welcome_app: {
        Intent intent = new Intent(SettingsActivity.this, CoverActivity.class);
        startActivity(intent);
      }
      break;
      case R.id.app_language: {
        Toast.makeText(this,"暂未实现",Toast.LENGTH_SHORT).show();
      }
      break;
      case R.id.about_app:
        AlertDialog.Builder dialog=new AlertDialog.Builder(SettingsActivity.this);
        dialog.setTitle("茶明白");
        dialog.setMessage("本版本为β版，部分功能暂未实现，已实现的功能存在一些漏洞，欢迎反馈！敬请期待正式版。");
        dialog.setCancelable(false);
        dialog.setPositiveButton("确定",new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
          }
        });
        dialog.show();
           break;
      case R.id.clear_cache: {
        clearCache();
      }
      break;
      default:
        break;

    }
  }
  private void clearCache() {
    try {
      String cacheSize = FileCacheUtils.getCacheSize(this.getCacheDir());
      FileCacheUtils.cleanInternalCache(this);
      Toast.makeText(this, "本次清理" + cacheSize + "缓存", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
